<template>
  <div class="sidebar-hero-list">
    <div class="header-tabs">
      <el-radio-group v-model="timeFilter" size="small">
        <el-radio-button label="week">本周</el-radio-button>
        <el-radio-button label="month">本月</el-radio-button>
        <el-radio-button label="all">总榜</el-radio-button>
      </el-radio-group>
    </div>
    
    <!-- 只显示前三名 -->
    <div class="top-heroes">
      <div 
        v-for="(hero, index) in topThreeHeroes" 
        :key="hero.id" 
        class="top-hero-card"
        :class="`rank-${index + 1}`"
      >
        <div class="rank-badge">{{ index + 1 }}</div>
        <div class="hero-info">
          <el-avatar :size="30" :src="hero.avatar" />
          <div class="hero-name">{{ hero.name }}</div>
        </div>
        <div class="hero-stats">
          <div class="stat-item">
            <div class="stat-value">{{ hero.returnedItems }}</div>
            <div class="stat-label">归还</div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 简化的表格，只显示4-7名 -->
    <div class="other-heroes">
      <div 
        v-for="(hero, index) in otherHeroes.slice(0, 4)" 
        :key="hero.id"
        class="other-hero-item"
      >
        <div class="rank-number">{{ index + 4 }}</div>
        <div class="hero-info">
          <div class="hero-name">{{ hero.name }}</div>
        </div>
        <div class="hero-stats">{{ hero.returnedItems }}</div>
      </div>
    </div>
    
    <div class="more-link">
      <el-button text type="primary" size="small">查看更多</el-button>
    </div>
  </div>
</template>

<script>
import { ref, computed } from 'vue';

export default {
  name: 'SidebarHeroList',
  setup() {
    const timeFilter = ref('month');
    
    // 模拟英雄榜数据
    const heroData = ref([
      {
        id: 1,
        name: '陈思源',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 42,
        helpedUsers: 38,
        honorTitle: '拾光使者',
      },
      {
        id: 2,
        name: '李明轩',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 36,
        helpedUsers: 32,
        honorTitle: '温暖传递官',
      },
      {
        id: 3,
        name: '张小雨',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 31,
        helpedUsers: 29,
        honorTitle: '爱心守护者',
      },
      {
        id: 4,
        name: '王浩然',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 28,
        helpedUsers: 25,
        honorTitle: '诚信先锋',
      },
      {
        id: 5,
        name: '林芳华',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 26,
        helpedUsers: 24,
        honorTitle: '微光传递者',
      },
      {
        id: 6,
        name: '赵子豪',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 24,
        helpedUsers: 22,
        honorTitle: '爱心大使',
      },
      {
        id: 7,
        name: '刘雨欣',
        avatar: 'https://img.shetu66.com/2023/08/02/1690966649671884.png',
        returnedItems: 22,
        helpedUsers: 20,
        honorTitle: '校园好人',
      }
    ]);
    
    const topThreeHeroes = computed(() => {
      return heroData.value.slice(0, 3);
    });
    
    const otherHeroes = computed(() => {
      return heroData.value.slice(3);
    });
    
    return {
      timeFilter,
      heroData,
      topThreeHeroes,
      otherHeroes
    };
  }
};
</script>

<style scoped>
.sidebar-hero-list {
  font-size: 0.85em;
  width: 100%;
}

.header-tabs {
  margin-bottom: 15px;
  display: flex;
  justify-content: center;
}

.top-heroes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.top-hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  border-radius: 6px;
  position: relative;
  background-color: #f5f7fa;
}

.top-hero-card.rank-1 {
  background: linear-gradient(135deg, #fff6e6, #ffd6a5);
}

.top-hero-card.rank-2 {
  background: linear-gradient(135deg, #f5f5f5, #e0e0e0);
}

.top-hero-card.rank-3 {
  background: linear-gradient(135deg, #fff0e6, #ffcdb2);
}

.rank-badge {
  position: absolute;
  top: 50%;
  left: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: #f56c6c;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 10px;
  transform: translateY(-50%);
}

.top-hero-card.rank-1 .rank-badge {
  background-color: #ff9900;
}

.top-hero-card.rank-2 .rank-badge {
  background-color: #909399;
}

.top-hero-card.rank-3 .rank-badge {
  background-color: #e6a23c;
}

.hero-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 15px;
}

.hero-name {
  font-weight: bold;
  color: #303133;
  font-size: 14px;
}

.hero-stats {
  display: flex;
  gap: 5px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 16px;
  font-weight: bold;
  color: #303133;
}

.stat-label {
  font-size: 10px;
  color: #909399;
}

.other-heroes {
  margin-bottom: 10px;
}

.other-hero-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid #f0f0f0;
}

.other-hero-item .rank-number {
  width: 18px;
  height: 18px;
  background-color: #f2f6fc;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #606266;
}

.other-hero-item .hero-info {
  flex: 1;
  margin-left: 10px;
}

.other-hero-item .hero-stats {
  font-weight: bold;
  color: #303133;
}

.more-link {
  text-align: center;
  margin-top: 10px;
}
</style> 